using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.ComponentModel;
using LeisureCenter.Api;

namespace LeisureCenter.Controls
{
    public abstract class LeisureCenterControl : Control, IFocusHandler
    {
        protected LeisureCenterControl()
        {
            KeyDown += new KeyEventHandler(FocusHandler.HandleControlKeyDown);
        }

        protected override bool ProcessDialogKey(Keys keyData)
        {
            if ((keyData & (Keys.Alt | Keys.Control)) == Keys.None)
            {
                Keys keys1 = keyData & Keys.KeyCode;
                switch (keys1)
                {
                    case Keys.Left:
                    case Keys.Up:
                    case Keys.Right:
                    case Keys.Down:
                        return false;
                }
            }
            return base.ProcessDialogKey(keyData);
        }

        protected override void OnEnter(EventArgs e)
        {
            base.OnEnter(e);
            Invalidate();
        }

        protected override void OnLeave(EventArgs e)
        {
            base.OnLeave(e);
            Invalidate();
        }

        #region IFocusHandler Membres

        private IFocusHandler left;
        [Category("Focus")]
        public IFocusHandler FocusLeft { get { return left; } set { if (value != this) left = value; } }

        private IFocusHandler right;
        [Category("Focus")]
        public IFocusHandler FocusRight { get { return right; } set { if (value != this) right = value; } }

        private IFocusHandler up;
        [Category("Focus")]
        public IFocusHandler FocusUp { get { return up; } set { if (value != this) up = value; } }

        private IFocusHandler down;
        [Category("Focus")]
        public IFocusHandler FocusDown { get { return down; } set { if (value != this) down = value; } }

        [Browsable(false)]
        public Control Control { get { return this; } }

        public bool SetFocus(IFocusHandler source, Keys key)
        {
            return FocusHandler.SetFocus(this, source, key);
        }

        #endregion
    }
}
